package com.yimi.yinhepda.db.table;

import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.table.DatabaseTable;
import com.pda.ym.entity.bean.CarPlanTaskEntity;
import com.pda.ym.entity.bean.LoadBillTaskEntity;
import com.yimi.yinhepda.db.dao.DepartmentTableDao;
import com.yimi.yinhepda.entity.response.QueryUnloadTask;
import com.yimi.yinhepda.utils.Common;
import com.pda.ym.utils.Constants;
import com.pda.ym.utils.SharedPreferUtil;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * @author 000432
 * @date 2017/4/8
 * 卸车任务表
 */
@DatabaseTable(tableName = "unloadTaskTable")
public class UnloadTaskTable implements Serializable {
    /**
     * 自增长的ID
     */
    @DatabaseField(generatedId = true)
    private Long id;
    /**
     * 任务号，关联扫描表
     */
    @DatabaseField(index = true)
    private String task;
    /**
     * 车线任务号
     */
    @DatabaseField
    private String taskNo;
    /**
     * 配载单号/车标号
     */
    @DatabaseField(index = true)
    private String stowageNo;
    /**
     * 本地使用: 上下一站部门类型
     */
    @DatabaseField
    private Integer relationDeptType;
    /**
     * 上一站编码
     */
    @DatabaseField
    private String srcDeptCode;
    /**
     * 上一站名称
     */
    @DatabaseField
    private String srcDeptName;
    /**
     * 下一站编号
     */
    @DatabaseField
    private String destDeptCode;
    /**
     * 下一站名称
     */
    @DatabaseField
    private String destDeptName;
    /**
     * 扫描人工号
     */
    @DatabaseField()
    private String operEmpCode;
    /**
     * 车牌号
     */
    @DatabaseField
    private String carNo;
    /**
     * 总重量
     */
    @DatabaseField
    private Double weight;
    /**
     * 总件数
     */
    @DatabaseField
    private Integer piecesNum;
    /**
     * 总票数
     */
    @DatabaseField
    private Integer priceNum;
    /**
     * 创建时间（yyyy-MM-dd HH:mm:ss）
     */
    @DatabaseField()
    private String createTime;
    /**
     * 0未完成 1完成
     */
    @DatabaseField()
    private Integer status = 0;
    /**
     * 0未上传 1已上传
     */
    @DatabaseField()
    private Integer isUpload = 0;
    /**
     * 本地配载单序号
     */
    @DatabaseField()
    private Integer stowageNoOrder;
    /**
     * 运输方式：1-trunk_line干线,2-branch_line支线,3-car_load:整车
     */
    @DatabaseField()
    private Integer bizTypeCode;
    /**
     * 扫描人姓名
     */
    @DatabaseField()
    private String operEmpName;
    /**
     * 列表显示时间（yyMMdd）
     */
    @DatabaseField()
    private String showTime;
    /**
     * 目的公司编码 （装车：下一站；卸车：登陆网点）
     */
    @DatabaseField()
    private String toCompCode;
    /**
     * 结束时间
     */
    @DatabaseField()
    private String endTime;
    /**
     * 封签号
     */
    @DatabaseField()
    private String sealSignNo;

    /**
     * 离线封车/解封时间，格式：yyyyMMddHHmmss
     */
    @DatabaseField()
    private String sealSignTime;

    /**
     * 装车类型：1-封车，2-未封车，3-卸车，4-未卸车，5-已解封，6-单独封车
     */
    @DatabaseField()
    private int loadType;
    /**
     * 离线任务号
     */
    @DatabaseField()
    private String offlineTaskNo;
    /**
     * 是否是整车：1-是，2-否
     */
    @DatabaseField()
    private int isCompleteCar;
    /**
     * 车标号
     */
    @DatabaseField()
    private String carMark;
    /**
     * 操作类型：1-装车。2-卸车
     */
    @DatabaseField()
    private int operType;

    public UnloadTaskTable(String task, String stowageNo, String srcDeptCode, String srcDeptName, String destDeptCode, String destDeptName,
                           String carNo, Double weight, Integer piecesNum, Integer priceNum, String createTime,
                           Integer status, Integer isUpload, String operEmpCode, String carMark, Integer relationDeptType) {
        this.task = task;
        this.stowageNo = stowageNo;
        this.srcDeptCode = srcDeptCode;
        this.srcDeptName = srcDeptName;
        this.destDeptCode = destDeptCode;
        this.destDeptName = destDeptName;
        this.carNo = carNo;
        this.weight = weight;
        this.piecesNum = piecesNum;
        this.priceNum = priceNum;
        this.createTime = createTime;
        this.status = status;
        this.isUpload = isUpload;
        this.operEmpCode = operEmpCode;
        this.carMark = carMark;
        this.relationDeptType = relationDeptType;
    }

    public String getTaskNo() {
        return taskNo;
    }

    public void setTaskNo(String taskNo) {
        this.taskNo = taskNo;
    }

    public Integer getRelationDeptType() {
        return relationDeptType;
    }

    public void setRelationDeptType(Integer relationDeptType) {
        this.relationDeptType = relationDeptType;
    }

    public int getOperType() {
        return operType;
    }

    public void setOperType(int operType) {
        this.operType = operType;
    }

    public String getCarMark() {
        return carMark;
    }

    public void setCarMark(String carMark) {
        this.carMark = carMark;
    }

    public String getSealSignTime() {
        return sealSignTime;
    }

    public void setSealSignTime(String sealSignTime) {
        this.sealSignTime = sealSignTime;
    }

    public int getIsCompleteCar() {
        return isCompleteCar;
    }

    public void setIsCompleteCar(int isCompleteCar) {
        this.isCompleteCar = isCompleteCar;
    }

    public UnloadTaskTable() {
    }

    public String getOfflineTaskNo() {
        return offlineTaskNo;
    }

    public void setOfflineTaskNo(String offlineTaskNo) {
        this.offlineTaskNo = offlineTaskNo;
    }

    public int getLoadType() {
        return loadType;
    }

    public void setLoadType(int loadType) {
        this.loadType = loadType;
    }

    public Integer getStowageNoOrder() {
        return stowageNoOrder;
    }

    public void setStowageNoOrder(Integer stowageNoOrder) {
        this.stowageNoOrder = stowageNoOrder;
    }

    public String getSealSignNo() {
        return sealSignNo;
    }

    public void setSealSignNo(String sealSignNo) {
        this.sealSignNo = sealSignNo;
    }

    public String getOperEmpCode() {
        return operEmpCode;
    }

    public void setOperEmpCode(String operEmpCode) {
        this.operEmpCode = operEmpCode;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getTask() {
        return task;
    }

    public void setTask(String task) {
        this.task = task;
    }

    public String getStowageNo() {
        if (stowageNo == null) {
            stowageNo = "";
        }
        return stowageNo;
    }

    public void setStowageNo(String stowageNo) {
        this.stowageNo = stowageNo;
    }

    public String getSrcDeptCode() {
        if (srcDeptCode == null) {
            srcDeptCode = "";
        }
        return srcDeptCode;
    }

    public void setSrcDeptCode(String srcDeptCode) {
        this.srcDeptCode = srcDeptCode;
    }

    public String getSrcDeptName() {
        if (srcDeptName == null) {
            srcDeptName = "";
        }
        return srcDeptName;
    }

    public void setSrcDeptName(String srcDeptName) {
        this.srcDeptName = srcDeptName;
    }

    public String getDestDeptCode() {
        if (destDeptCode == null) {
            destDeptCode = "";
        }
        return destDeptCode;
    }

    public void setDestDeptCode(String destDeptCode) {
        this.destDeptCode = destDeptCode;
    }

    public String getDestDeptName() {
        if (destDeptName == null) {
            destDeptName = "";
        }
        return destDeptName;
    }

    public void setDestDeptName(String destDeptName) {
        this.destDeptName = destDeptName;
    }

    public String getCarNo() {
        if (carNo == null) {
            carNo = "";
        }
        return carNo;
    }

    public void setCarNo(String carNo) {
        this.carNo = carNo;
    }

    public Double getWeight() {
        if (weight == null) {
            weight = new Double(0);
        }
        return weight;
    }

    public void setWeight(Double weight) {
        this.weight = weight;
    }

    public Integer getPiecesNum() {
        if (piecesNum == null) {
            piecesNum = 0;
        }
        return piecesNum;
    }

    public void setPiecesNum(Integer piecesNum) {
        this.piecesNum = piecesNum;
    }

    public Integer getPriceNum() {
        if (priceNum == null) {
            priceNum = 0;
        }
        return priceNum;
    }

    public void setPriceNum(Integer priceNum) {
        this.priceNum = priceNum;
    }

    public String getCreateTime() {
        return createTime;
    }

    public void setCreateTime(String createTime) {
        this.createTime = createTime;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public Integer getIsUpload() {
        return isUpload;
    }

    public void setIsUpload(Integer isUpload) {
        this.isUpload = isUpload;
    }

    public static List<UnloadTaskTable> parse(String task, List<QueryUnloadTask> list) {
        if (list == null || list.size() == 0) {
            return null;
        }
        String createTime = Constants.GetSysTime();
        DepartmentTableDao departmentTableDao = new DepartmentTableDao();
        List<UnloadTaskTable> listUnloadTaskTable = new ArrayList<UnloadTaskTable>();
        for (QueryUnloadTask item : list) {
            DepartmentTable departmentTable = departmentTableDao.queryDeptByDeptCode(item.getSrcDeptCode());
            UnloadTaskTable mUnloadTaskTable =
                    new UnloadTaskTable(task, item.getStowageNo(), item.getSrcDeptCode(), item.getSrcDeptName(), item.getDestDeptCode(), item.getDestDeptName(),
                            item.getCarNo(), item.getWeight().doubleValue(), item.getPiecesNum(), item.getPriceNum(), createTime, 0, 0,
                            SharedPreferUtil.getInstance().getValue(Common.USER_CODE), item.getCarMark(), departmentTable != null ? departmentTable.getDeptType() : null);
            listUnloadTaskTable.add(mUnloadTaskTable);
        }
        return listUnloadTaskTable;
    }

    public Integer getOrder() {
        return stowageNoOrder;
    }

    public void setOrder(Integer order) {
        this.stowageNoOrder = order;
    }

    public Integer getBizTypeCode() {
        return bizTypeCode;
    }

    public void setBizTypeCode(Integer bizTypeCode) {
        this.bizTypeCode = bizTypeCode;
    }

    public String getOperEmpName() {
        return operEmpName;
    }

    public void setOperEmpName(String operEmpName) {
        this.operEmpName = operEmpName;
    }

    public String getShowTime() {
        return showTime;
    }

    public void setShowTime(String showTime) {
        this.showTime = showTime;
    }

    public String getToCompCode() {
        return toCompCode;
    }

    public void setToCompCode(String toCompCode) {
        this.toCompCode = toCompCode;
    }

    public String getEndTime() {
        return endTime;
    }

    public void setEndTime(String endTime) {
        this.endTime = endTime;
    }

    /**
     * 用于装卸车任务列表装卸车时，选中的任务暂存至任务表中
     *
     * @param task     任务号
     * @param list     卸车任务集合
     * @param operType 1-装车，2-卸车
     * @return 卸车暂存任务集合
     */
    public static List<UnloadTaskTable> parseUnloadTable(String task, List<CarPlanTaskEntity> list, int operType) {
        if (list == null || list.isEmpty()) {
            return null;
        }
        String createTime = Constants.GetSysTime();
        DepartmentTableDao departmentTableDao = new DepartmentTableDao();
        List<UnloadTaskTable> listUnloadTaskTable = new ArrayList<>();
        for (CarPlanTaskEntity unloadTask : list) {
            if (unloadTask.isCheck()) {
                if(unloadTask.getLoadTasks() != null){
                    for (LoadBillTaskEntity item : unloadTask.getLoadTasks()) {
                        DepartmentTable departmentTable = departmentTableDao.queryDeptByDeptCode(item.getSrcDeptCode());
                        UnloadTaskTable mUnloadTaskTable =
                                new UnloadTaskTable(task, item.getStowageNo(), item.getSrcDeptCode(), item.getSrcDeptName(), item.getDestDeptCode(), item.getDestDeptName(),
                                        item.getCarNo(), item.getWeight(), item.getPiecesNum(), item.getPriceNum(), createTime, 0, 0,
                                        SharedPreferUtil.getInstance().getValue(Common.USER_CODE), item.getStowageNo(), departmentTable != null ? departmentTable.getDeptType() : null);
                        //设置卸车类型
                        mUnloadTaskTable.setOperType(operType);
                        mUnloadTaskTable.setBizTypeCode(item.getBizTypeCode());
                        //车线任务号
                        mUnloadTaskTable.setTaskNo(unloadTask.getTaskNo());
                        listUnloadTaskTable.add(mUnloadTaskTable);
                    }
                }
            }
        }
        return listUnloadTaskTable;
    }

    /**
     * 用于装卸组装卸车时判断任务是否被选中，选中的暂存至任务表中
     *
     * @param task     任务号
     * @param list     卸车任务集合
     * @param operType 1-装车，2-卸车
     * @return 卸车暂存任务结合
     */
    public static List<UnloadTaskTable> parseUnloadTable2(String task, List<CarPlanTaskEntity> list, int operType) {
        if (list == null || list.isEmpty()) {
            return null;
        }
        String createTime = Constants.GetSysTime();
        DepartmentTableDao departmentTableDao = new DepartmentTableDao();
        List<UnloadTaskTable> listUnloadTaskTable = new ArrayList<>();
        for (CarPlanTaskEntity unloadTask : list) {
            if(unloadTask.getLoadTasks() != null){
                for (LoadBillTaskEntity item : unloadTask.getLoadTasks()) {
                    if (item.isCheck()) {
                        DepartmentTable departmentTable = departmentTableDao.queryDeptByDeptCode(item.getSrcDeptCode());
                        UnloadTaskTable mUnloadTaskTable =
                                new UnloadTaskTable(task, item.getStowageNo(), item.getSrcDeptCode(), item.getSrcDeptName(), item.getDestDeptCode(), item.getDestDeptName(),
                                        item.getCarNo(), item.getWeight(), item.getPiecesNum(), item.getPriceNum(), createTime, 0, 0,
                                        SharedPreferUtil.getInstance().getValue(Common.USER_CODE), item.getStowageNo(), departmentTable != null ? departmentTable.getDeptType() : null);
                        //设置卸车类型
                        mUnloadTaskTable.setOperType(operType);
                        mUnloadTaskTable.setBizTypeCode(item.getBizTypeCode());
                        //车线任务号
                        mUnloadTaskTable.setTaskNo(unloadTask.getTaskNo());
                        listUnloadTaskTable.add(mUnloadTaskTable);
                    }
                }
            }
        }
        return listUnloadTaskTable;
    }
}
